package cn.org.eshow.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;

/**
 * 地址表
 */
@Entity
@Table(name = "address")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Address extends BaseObject implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Integer id;//地址ID

    @Column(name = "add_time")
    private Date addTime = new Date();// 添加时间

    @Column(name = "update_time")
    private Date updateTime = new Date();// 更新时间

    @Column(length = 100)
    private String addr;// 地址

    @Column(length = 10)
    private String zip;// 邮编

    @Column(length = 30)
    private String name;// 姓名

    @Column(length = 20)
    private String mobile;// 手机

    @Column
    private Double lng;//经度

    @Column
    private Double lat;//纬度

    @Column(length = 50)
    private String weixin;// 微信

    @Column(name = "if_default", length = 1)
    private Boolean ifDefault;// 是否默认地址

    @Column
    private Boolean enabled = Boolean.TRUE;//是否可用


    @Column
    private String province;// 省

    @Column
    private String city;// 城市

    @Column
    private String district;// 区县

    @JsonIgnore
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "user_id")
    private User user;// 用户

    public Address() {
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Date getAddTime() {
        return addTime;
    }

    public void setAddTime(Date addTime) {
        this.addTime = addTime;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    public String getAddr() {
        return addr;
    }

    public void setAddr(String addr) {
        this.addr = addr;
    }

    public String getZip() {
        return zip;
    }

    public void setZip(String zip) {
        this.zip = zip;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    public Double getLng() {
        return lng;
    }

    public void setLng(Double lng) {
        this.lng = lng;
    }

    public Double getLat() {
        return lat;
    }

    public void setLat(Double lat) {
        this.lat = lat;
    }

    public String getWeixin() {
        return weixin;
    }

    public void setWeixin(String weixin) {
        this.weixin = weixin;
    }

    public Boolean getIfDefault() {
        return ifDefault;
    }

    public void setIfDefault(Boolean ifDefault) {
        this.ifDefault = ifDefault;
    }

    public Boolean getEnabled() {
        return enabled;
    }

    public void setEnabled(Boolean enabled) {
        this.enabled = enabled;
    }

    public String getProvince() {
        return province;
    }

    public void setProvince(String province) {
        this.province = province;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getDistrict() {
        return district;
    }

    public void setDistrict(String district) {
        this.district = district;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public boolean equals(Object o) {
        if (this == o)
            return true;
        if (o == null || getClass() != o.getClass())
            return false;

        Address pojo = (Address) o;
        if (id != null ? !id.equals(pojo.id) : pojo.id != null)
            return false;
        if (addTime != null ? !addTime.equals(pojo.addTime) : pojo.addTime != null)
            return false;
        if (updateTime != null ? !updateTime.equals(pojo.updateTime) : pojo.updateTime != null)
            return false;
        if (addr != null ? !addr.equals(pojo.addr) : pojo.addr != null)
            return false;
        if (zip != null ? !zip.equals(pojo.zip) : pojo.zip != null)
            return false;
        if (name != null ? !name.equals(pojo.name) : pojo.name != null)
            return false;
        if (mobile != null ? !mobile.equals(pojo.mobile) : pojo.mobile != null)
            return false;
        if (lng != null ? !lng.equals(pojo.lng) : pojo.lng != null)
            return false;
        if (lat != null ? !lat.equals(pojo.lat) : pojo.lat != null)
            return false;
        if (weixin != null ? !weixin.equals(pojo.weixin) : pojo.weixin != null)
            return false;
        if (ifDefault != null ? !ifDefault.equals(pojo.ifDefault) : pojo.ifDefault != null)
            return false;
        if (enabled != null ? !enabled.equals(pojo.enabled) : pojo.enabled != null)
            return false;
        if (province != null ? !province.equals(pojo.province) : pojo.province != null)
            return false;
        if (city != null ? !city.equals(pojo.city) : pojo.city != null)
            return false;
        if (district != null ? !district.equals(pojo.district) : pojo.district != null)
            return false;
        if (user != null ? !user.equals(pojo.user) : pojo.user != null)
            return false;

        return true;
    }

    public int hashCode() {
        int result = 0;
        result = result + (id != null ? id.hashCode() : 0);
        result = 31 * result + (addTime != null ? addTime.hashCode() : 0);
        result = 31 * result + (updateTime != null ? updateTime.hashCode() : 0);
        result = 31 * result + (addr != null ? addr.hashCode() : 0);
        result = 31 * result + (zip != null ? zip.hashCode() : 0);
        result = 31 * result + (name != null ? name.hashCode() : 0);
        result = 31 * result + (mobile != null ? mobile.hashCode() : 0);
        result = 31 * result + (lng != null ? lng.hashCode() : 0);
        result = 31 * result + (lat != null ? lat.hashCode() : 0);
        result = 31 * result + (weixin != null ? weixin.hashCode() : 0);
        result = 31 * result + (ifDefault != null ? ifDefault.hashCode() : 0);
        result = 31 * result + (enabled != null ? enabled.hashCode() : 0);
        result = 31 * result + (province != null ? province.hashCode() : 0);
        result = 31 * result + (city != null ? city.hashCode() : 0);
        result = 31 * result + (district != null ? district.hashCode() : 0);
        result = 31 * result + (user != null ? user.hashCode() : 0);
        return result;
    }

    public String toString() {
        return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
                .append("id", this.id)
                .append("addTime", this.addTime)
                .append("updateTime", this.updateTime)
                .append("addr", this.addr)
                .append("zip", this.zip)
                .append("name", this.name)
                .append("mobile", this.mobile)
                .append("lng", this.lng)
                .append("lat", this.lat)
                .append("weixin", this.weixin)
                .append("ifDefault", this.ifDefault)
                .append("enabled", this.enabled)
                .append("province", this.province)
                .append("city", this.city)
                .append("district", this.district)
                .append("user", this.user)
                .toString();
    }
}
